package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类查询数量
     * @param id
     * @return
     */
    @Select("select count(id) from dish where category_id =#{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void save(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> querySelect(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id查询菜品
     * @param CategoryId
     */
    @Select("select * from dish where category_id = #{CategoryId}")
    List<Dish> selectByCategoryId(Long CategoryId);

    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id修改菜品
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    @Select("select * from  dish where id = #{id}")
    Dish selectById(Long id);

    /**
     * 根据多连表查询套餐id查询菜品表
     * @param setmealId
     */
    @Select("SELECT d.*  FROM dish d LEFT JOIN setmeal_dish s ON d.id = s.dish_id WHERE s.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);
}
